// pages/other/self/self.js

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    haveImg: app.globalData.haveImg,
    bgimg1: app.globalData.bgimg,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.globalData.userInfo.userInfo)
    var info = app.globalData.userInfo.userInfo
    if(info==1) var gender='male'
    else var gender ='female'
    this.setData({
      src:info.avatar,
      nickName:info.name,
      gender:gender,
      city:info.city,
      province:info.province,
      country:info.country,
      bgimg1: app.globalData.bgimg,
      haveImg: app.globalData.haveImg
    })

  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  infoSubmit: function (e) {
    //修改内容
    console.log(e);
    var token = app.globalData.userInfo.token
    var info = app.globalData.userInfo.userInfo;
    var city = e.detail.value[2];
    var country = e.detail.value[1];
    var province = e.detail.value[0];
    var avatarUrl=info.avatar;
    var language=info.language;
    var that = this;
    wx.request({
      // url: 'https://mockapi.eolinker.com/SN5C9Ybd511179abd037ba7a2443cbd1f4885103f842b3e/user/modifyUser',
      url:'https://sdu-miniprogram.cn:8888/api/miniprogram/user/modifyUser',
      method: 'POST',
      data: {
        token:token,
        user:{
        id:info.id,
        nickName: e.detail.value.nickName,
        gender: e.detail.value.gender,
        avatarUrl:avatarUrl,
        language:language,
        country: country,
        province: province,
        city: city
        }
      },
      success: function (res) {
        console.log(res)
        //刷新数据
        
      }
    })

  },
  changeRegin: function (e) {
    console.log(e)

    this.globalData.city = e.detail.value[0],
    this.globalData.province = e.detail.value[1],
      this.globalData.country = e.detail.value[2]

  },
  globalData: {
    city: '',
    province: '',
    country: ''
  }
})